

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>增加/删除 OSD &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="增加/删除监视器" href="../add-or-rm-mons/" />
    <link rel="prev" title="Configure Monitor Election Strategies" href="../change-mon-elections/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../">Ceph 存储集群</a> &raquo;</li>
        
          <li><a href="../">集群运维</a> &raquo;</li>
        
      <li>增加/删除 OSD</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../../_sources/rados/operations/add-or-rm-osds.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../">
          

          
            
            <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../">Ceph 存储集群</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../configuration/">配置</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../">运维</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../operating/">操纵集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../health-checks/">健康检查</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring/">监控集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring-osd-pg/">监控 OSD 和归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../user-management/">用户管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pg-repair/">修复 PG 不一致状态</a></li>
<li class="toctree-l3"><a class="reference internal" href="../data-placement/">数据归置概览</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pools/">存储池</a></li>
<li class="toctree-l3"><a class="reference internal" href="../erasure-code/">纠删码</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cache-tiering/">分级缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../placement-groups/">归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../balancer/">均衡器</a></li>
<li class="toctree-l3"><a class="reference internal" href="../upmap/">使用 pg-upmap</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map/">CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map-edits/">手动编辑一个 CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../stretch-mode/">Stretch Clusters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../change-mon-elections/">Configure Monitor Election Strategies</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">增加/删除 OSD</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id1">增加 OSD</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id13">删除 OSD （手动）</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../add-or-rm-mons/">增加/删除监视器</a></li>
<li class="toctree-l3"><a class="reference internal" href="../devices/">设备管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bluestore-migration/">迁移到 BlueStore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../control/">命令参考</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/community/">Ceph 社区</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-mon/">监视器故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-osd/">OSD 故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-pg/">归置组排障</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/log-and-debug/">日志记录和调试</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/cpu-profiling/">CPU 剖析</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/memory-profiling/">内存剖析</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../man/">    手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../troubleshooting/">故障排除</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="osd">
<h1>增加/删除 OSD<a class="headerlink" href="#osd" title="Permalink to this headline">¶</a></h1>
<p>如果您的集群已经在运行，你可以在运行时添加或删除 OSD 。</p>
<div class="section" id="id1">
<h2>增加 OSD<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<p>你迟早要扩容集群， Ceph 允许在运行时增加 OSD 。在 Ceph 里，一个
OSD 一般是一个 <code class="docutils literal notranslate"><span class="pre">ceph-osd</span></code> 守护进程，它运行在硬盘之上，如果你有多个硬盘，可以给每个硬盘启动一个 <code class="docutils literal notranslate"><span class="pre">ceph-osd</span></code> 守护进程。</p>
<p>通常，你应该监控集群容量，看是否达到了容量上限，因为达到了它的
<code class="docutils literal notranslate"><span class="pre">near</span> <span class="pre">full</span></code> 比率后，要增加一或多个 OSD 来扩容。</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>不要等空间满了再增加 OSD ，空间使用率达到
<code class="docutils literal notranslate"><span class="pre">near</span> <span class="pre">full</span></code> 比率后， OSD 失败可能导致集群空间占满。</p>
</div>
<div class="section" id="id2">
<h3>部署硬件<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<p>如果你通过增加主机来增加 OSD ，关于 OSD 服务器硬件的配置请参见<a class="reference external" href="../../../start/hardware-recommendations">硬件推荐</a>。要把一台 OSD 主机加入到集群，首先要安装最新版的 Linux ，而且存储硬盘要做好必要的准备，详情参见<a class="reference external" href="../../configuration/filesystem-recommendations">文件系统推荐</a>。</p>
<p>把 OSD 主机安装到集群机架上，连接好网络、确保网络通畅。详情见<a class="reference external" href="../../configuration/network-config-ref">网络配置参考</a>。</p>
</div>
<div class="section" id="id6">
<h3>安装必要软件<a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h3>
<p>在手动部署的集群里，你必须手动安装 Ceph 软件包，详情见<a class="reference external" href="../../../install">安装 Ceph （手动）</a>。你应该配置一个无密码登录 SSH 的用户，且他有 root 权限。</p>
</div>
<div class="section" id="id7">
<h3>增加 OSD （手动）<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3>
<p>此过程要设置一个 <code class="docutils literal notranslate"><span class="pre">ceph-osd</span></code> 守护进程，让它使用一个硬盘，且让集群把数据发布到 OSD 。如果一台主机有多个硬盘，可以重复此过程，把每个硬盘配置为一个 OSD 。</p>
<p>要添加 OSD ，要依次创建数据目录、把硬盘挂载到目录、把 OSD 加入集群、然后把它加入 CRUSH 图。</p>
<p>往 CRUSH 图里添加 OSD 时建议设置权重，硬盘容量每年增长 40% ，所以较新的 OSD 主机拥有更大的空间（即它们可以有更大的权重）。</p>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>Ceph 喜欢统一的硬件，与存储池无关。如果你要新增容量不一的驱动器，还需调整它们的权重。但是，为实现最佳性能，
CRUSH 的分级结构最好按类型、容量定义。</p>
</div>
<ol class="arabic">
<li><p>创建 OSD 。如果未指定 UUID ， OSD 启动时会自动生成一个。下列命令会输出 OSD 号，后续步骤你会用到。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">create</span> <span class="p">[{</span><span class="n">uuid</span><span class="p">}</span> <span class="p">[{</span><span class="nb">id</span><span class="p">}]]</span>
</pre></div>
</div>
<p>如果指定了可选参数 {id} ，那么它将作为 OSD id 。要注意，如果此数字已使用，此命令会出错。</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>一般来说，我们不建议指定 {id} 。因为 ID 是按照数组分配的，跳过一些依然会浪费内存；尤其是跳过太多、或者集群很大时，会更明显。若未指定 {id} ，将用最小可用数字。</p>
</div>
</li>
<li><p>在新 OSD 主机上创建默认目录。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">new</span><span class="o">-</span><span class="n">osd</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
<span class="n">sudo</span> <span class="n">mkdir</span> <span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">osd</span><span class="o">/</span><span class="n">ceph</span><span class="o">-</span><span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">number</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>如果准备用于 OSD 的是单独的而非系统盘，先把它挂载到刚创建的目录下：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">new</span><span class="o">-</span><span class="n">osd</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
<span class="n">sudo</span> <span class="n">mkfs</span> <span class="o">-</span><span class="n">t</span> <span class="p">{</span><span class="n">fstype</span><span class="p">}</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="p">{</span><span class="n">drive</span><span class="p">}</span>
<span class="n">sudo</span> <span class="n">mount</span> <span class="o">-</span><span class="n">o</span> <span class="n">user_xattr</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="p">{</span><span class="n">hdd</span><span class="p">}</span> <span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">osd</span><span class="o">/</span><span class="n">ceph</span><span class="o">-</span><span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">number</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>初始化 OSD 数据目录。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">new</span><span class="o">-</span><span class="n">osd</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
<span class="n">ceph</span><span class="o">-</span><span class="n">osd</span> <span class="o">-</span><span class="n">i</span> <span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span> <span class="o">--</span><span class="n">mkfs</span> <span class="o">--</span><span class="n">mkkey</span>
</pre></div>
</div>
<p>运行 <code class="docutils literal notranslate"><span class="pre">ceph-osd</span></code> 时目录必须是空的。</p>
</li>
<li><p>注册 OSD 认证密钥， <code class="docutils literal notranslate"><span class="pre">ceph-{osd-num}</span></code> 路径里的 <code class="docutils literal notranslate"><span class="pre">ceph</span></code> 值应该是 <code class="docutils literal notranslate"><span class="pre">$cluster-$id</span></code> ，如果你的集群名字不是 <code class="docutils literal notranslate"><span class="pre">ceph</span></code> ，那就用改过的名字。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">auth</span> <span class="n">add</span> <span class="n">osd</span><span class="o">.</span><span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span> <span class="n">osd</span> <span class="s1">&#39;allow *&#39;</span> <span class="n">mon</span> <span class="s1">&#39;allow rwx&#39;</span> <span class="o">-</span><span class="n">i</span> <span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">osd</span><span class="o">/</span><span class="n">ceph</span><span class="o">-</span><span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span><span class="o">/</span><span class="n">keyring</span>
</pre></div>
</div>
</li>
<li><p>把 OSD 加入 CRUSH 图，这样它才开始收数据。用 <code class="docutils literal notranslate"><span class="pre">ceph</span> <span class="pre">osd</span> <span class="pre">crush</span> <span class="pre">add</span></code>
命令把 OSD 加入 CRUSH 分级结构的合适位置。如果你指定了不止一个桶，此命令会把它加入你所指定的桶中最具体的一个，<em>并且</em>把此桶挪到你指定的其它桶之内。<strong>重要：</strong>如果你只指定了 root 桶，此命令会把 OSD 直接挂到 root 下面，但是
CRUSH 规则期望它位于主机内。</p>
<p>执行下列命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">crush</span> <span class="n">add</span> <span class="p">{</span><span class="nb">id</span><span class="o">-</span><span class="ow">or</span><span class="o">-</span><span class="n">name</span><span class="p">}</span> <span class="p">{</span><span class="n">weight</span><span class="p">}</span>  <span class="p">[{</span><span class="n">bucket</span><span class="o">-</span><span class="nb">type</span><span class="p">}</span><span class="o">=</span><span class="p">{</span><span class="n">bucket</span><span class="o">-</span><span class="n">name</span><span class="p">}</span> <span class="o">...</span><span class="p">]</span>
</pre></div>
</div>
<p>你也可以反编译 CRUSH 图、把 OSD 加入设备列表、以桶的形式加入主机（如果它没在 CRUSH 图里）、以条目形式把设备加入主机、分配权重、重编译并应用它。详情参见<a class="reference external" href="../crush-map#addosd">增加/移动 OSD</a> 。</p>
</li>
</ol>
</div>
<div class="section" id="rados-replacing-an-osd">
<span id="id8"></span><h3>替换一个 OSD<a class="headerlink" href="#rados-replacing-an-osd" title="Permalink to this headline">¶</a></h3>
<p>当磁盘损坏、或者某管理员想用新后端重新开通 OSD ，比如从
FileStore 切换到 BlueStore ，这时候就需要更换 OSD 。不像<a class="reference external" href="../crush-map#removeosd">删除 OSD</a> ，要更换的 OSD ，在经历销毁后，其 id 和 CRUSH 图条目都需要保持不变。</p>
<ol class="arabic">
<li><p>确保销毁此 OSD 不会有问题：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>while ! ceph osd safe-to-destroy osd.{id} ; do sleep 10 ; done
</pre></div>
</div>
</li>
<li><p>先销毁这个 OSD:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">destroy</span> <span class="p">{</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">yes</span><span class="o">-</span><span class="n">i</span><span class="o">-</span><span class="n">really</span><span class="o">-</span><span class="n">mean</span><span class="o">-</span><span class="n">it</span>
</pre></div>
</div>
</li>
<li><p>如果这个硬盘之前另作他用，先擦除它再用于新 OSD 。对于新磁盘没必要：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span><span class="o">-</span><span class="n">volume</span> <span class="n">lvm</span> <span class="n">zap</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdX</span>
</pre></div>
</div>
</li>
<li><p>用销毁前的 OSD id 来准备这个磁盘：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span><span class="o">-</span><span class="n">volume</span> <span class="n">lvm</span> <span class="n">prepare</span> <span class="o">--</span><span class="n">osd</span><span class="o">-</span><span class="nb">id</span> <span class="p">{</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">data</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdX</span>
</pre></div>
</div>
</li>
<li><p>然后激活此 OSD ：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span><span class="o">-</span><span class="n">volume</span> <span class="n">lvm</span> <span class="n">activate</span> <span class="p">{</span><span class="nb">id</span><span class="p">}</span> <span class="p">{</span><span class="n">fsid</span><span class="p">}</span>
</pre></div>
</div>
</li>
</ol>
<p>或者，不需要准备再激活，只需一个命令即可完成重建，如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span><span class="o">-</span><span class="n">volume</span> <span class="n">lvm</span> <span class="n">create</span> <span class="o">--</span><span class="n">osd</span><span class="o">-</span><span class="nb">id</span> <span class="p">{</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">data</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdX</span>
</pre></div>
</div>
</div>
<div class="section" id="id9">
<h3>启动 OSD<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h3>
<p>把 OSD 加入 Ceph 后， OSD 就在配置里了。然而它还没运行，它现在的状态为 <code class="docutils literal notranslate"><span class="pre">down</span></code> 且 <code class="docutils literal notranslate"><span class="pre">in</span></code> 。你必须先启动 OSD 它才能收数据。可以用管理主机上的 <code class="docutils literal notranslate"><span class="pre">service</span> <span class="pre">ceph</span></code> 、或从 OSD 所在主机启动:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sudo</span> <span class="n">systemctl</span> <span class="n">start</span> <span class="n">ceph</span><span class="o">-</span><span class="n">osd</span><span class="o">@</span><span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span>
</pre></div>
</div>
<p>一旦你启动了 OSD ，其状态就变成了 <code class="docutils literal notranslate"><span class="pre">up</span></code> 且 <code class="docutils literal notranslate"><span class="pre">in</span></code> 。</p>
</div>
<div class="section" id="id10">
<h3>观察数据迁移<a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h3>
<p>把新 OSD 加入 CRUSH 图后， Ceph 会重新均衡服务器，一些归置组会迁移到新 OSD 里，你可以用 <a class="reference external" href="../monitoring">ceph</a> 命令观察此过程。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="o">-</span><span class="n">w</span>
</pre></div>
</div>
<p>你会看到归置组状态从 <code class="docutils literal notranslate"><span class="pre">active+clean</span></code> 变为
<code class="docutils literal notranslate"><span class="pre">active,</span> <span class="pre">some</span> <span class="pre">degraded</span> <span class="pre">objects</span></code> （有降级的对象）、且迁移完成后回到 <code class="docutils literal notranslate"><span class="pre">active+clean</span></code> 状态。（ Ctrl-c 退出）</p>
</div>
</div>
<div class="section" id="id13">
<h2>删除 OSD （手动）<a class="headerlink" href="#id13" title="Permalink to this headline">¶</a></h2>
<p>要想缩减集群尺寸或替换硬件，可在运行时删除 OSD 。在 Ceph 里，一个 OSD 通常是一台主机上的一个 <code class="docutils literal notranslate"><span class="pre">ceph-osd</span></code> 守护进程、它运行在一个硬盘之上。如果一台主机上有多个数据盘，你得挨个删除其对应
<code class="docutils literal notranslate"><span class="pre">ceph-osd</span></code> 。通常，操作前应该检查集群容量，看是否快达到上限了，确保删除 OSD 后不会使集群达到 <code class="docutils literal notranslate"><span class="pre">near</span> <span class="pre">full</span></code> 比率。</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>删除 OSD 时不要让集群达到 <code class="docutils literal notranslate"><span class="pre">full</span> <span class="pre">ratio</span></code> 值，删除
OSD 可能导致集群达到或超过 <code class="docutils literal notranslate"><span class="pre">full</span> <span class="pre">ratio</span></code> 值。</p>
</div>
<div class="section" id="id14">
<h3>把 OSD 踢出集群<a class="headerlink" href="#id14" title="Permalink to this headline">¶</a></h3>
<p>删除 OSD 前，它通常是 <code class="docutils literal notranslate"><span class="pre">up</span></code> 且 <code class="docutils literal notranslate"><span class="pre">in</span></code> 的，要先把它踢出集群，以使 Ceph 启动重新均衡、把数据拷贝到其他 OSD 。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">out</span> <span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="id15">
<h3>观察数据迁移<a class="headerlink" href="#id15" title="Permalink to this headline">¶</a></h3>
<p>一旦把 OSD 踢出（ <code class="docutils literal notranslate"><span class="pre">out</span></code> ）集群， Ceph 就会开始重新均衡集群、把归置组迁出将删除的 OSD 。你可以用 <a class="reference external" href="../monitoring">ceph</a> 工具观察此过程。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="o">-</span><span class="n">w</span>
</pre></div>
</div>
<p>你会看到归置组状态从 <code class="docutils literal notranslate"><span class="pre">active+clean</span></code> 变为
<code class="docutils literal notranslate"><span class="pre">active,</span> <span class="pre">some</span> <span class="pre">degraded</span> <span class="pre">objects</span></code> 、迁移完成后最终回到
<code class="docutils literal notranslate"><span class="pre">active+clean</span></code> 状态。（ Ctrl-c 中止）</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>有时候，（通常是只有几台主机的“小”集群，比如小型测试集群）拿出（ <code class="docutils literal notranslate"><span class="pre">out</span></code> ）某个 OSD 可能会使 CRUSH 进入临界状态，这时某些 PG 一直卡在 <code class="docutils literal notranslate"><span class="pre">active+remapped</span></code> 状态。如果遇到了这种情况，你应该把此 OSD 标记为 <code class="docutils literal notranslate"><span class="pre">in</span></code> ，用这个命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>``ceph osd in {osd-num}``
</pre></div>
</div>
<p>等回到最初的状态后，把它的权重设置为 0 ，而不是标记为
<code class="docutils literal notranslate"><span class="pre">out</span></code> ，用此命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>``ceph osd crush reweight osd.{osd-num} 0``
</pre></div>
</div>
<p>执行后，你可以观察数据迁移过程，应该可以正常结束。把某一 OSD
标记为 <code class="docutils literal notranslate"><span class="pre">out</span></code> 和权重改为 0 的区别在于，前者，包含此 OSD 的桶、其权重没变；而后一种情况下，桶的权重变了（降低了此 OSD
的权重）。某些情况下， reweight 命令更适合“小”集群。</p>
</div>
</div>
<div class="section" id="id16">
<h3>停止 OSD<a class="headerlink" href="#id16" title="Permalink to this headline">¶</a></h3>
<p>把 OSD 踢出集群后，它可能仍在运行，就是说其状态为 <code class="docutils literal notranslate"><span class="pre">up</span></code> 且
<code class="docutils literal notranslate"><span class="pre">out</span></code> 。删除前要先停止 OSD 进程。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
<span class="n">sudo</span> <span class="n">systemctl</span> <span class="n">stop</span> <span class="n">ceph</span><span class="o">-</span><span class="n">osd</span><span class="o">@</span><span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span>
</pre></div>
</div>
<p>停止 OSD 后，状态变为 <code class="docutils literal notranslate"><span class="pre">down</span></code> 。</p>
</div>
<div class="section" id="id17">
<h3>删除 OSD<a class="headerlink" href="#id17" title="Permalink to this headline">¶</a></h3>
<p>此步骤依次把一个 OSD 移出集群运行图、删除认证密钥、删除
OSD 运行图条目、删除 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 条目。如果主机有多个硬盘，每个硬盘对应的 OSD 都得重复此步骤。</p>
<ol class="arabic">
<li><p>首先，让集群忘掉这个 OSD 。这一步会从 CRUSH 图中删掉这个
OSD 、删除其认证密钥，也会从 OSD 运行图中删掉。请注意，
<a class="reference internal" href="../../../man/8/ceph/#ceph-admin-osd"><span class="std std-ref">purge 子命令</span></a> 在 Luminous 中才引进，老版本继续往下看：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">purge</span> <span class="p">{</span><span class="nb">id</span><span class="p">}</span> <span class="o">--</span><span class="n">yes</span><span class="o">-</span><span class="n">i</span><span class="o">-</span><span class="n">really</span><span class="o">-</span><span class="n">mean</span><span class="o">-</span><span class="n">it</span>
</pre></div>
</div>
</li>
<li><p>登录保存着 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 主副本的主机：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="p">{</span><span class="n">admin</span><span class="o">-</span><span class="n">host</span><span class="p">}</span>
<span class="n">cd</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">ceph</span>
<span class="n">vim</span> <span class="n">ceph</span><span class="o">.</span><span class="n">conf</span>
</pre></div>
</div>
</li>
<li><p>删除 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 文件内的相关 OSD 条目（如果还有的话）：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">osd</span><span class="mf">.1</span><span class="p">]</span>
        <span class="n">host</span> <span class="o">=</span> <span class="p">{</span><span class="n">hostname</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>在保存着 <code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 文件主副本的主机上操作，把更新过的
<code class="docutils literal notranslate"><span class="pre">ceph.conf</span></code> 文件复制到集群内其余主机的 <code class="docutils literal notranslate"><span class="pre">/etc/ceph</span></code> 目录下。</p></li>
</ol>
<p>如果你的 Ceph 集群版本低于 Luminous ，就不能用
<code class="docutils literal notranslate"><span class="pre">ceph</span> <span class="pre">osd</span> <span class="pre">purge</span></code> 子命令，需要手动执行如下步骤：</p>
<ol class="arabic">
<li><p>删除 CRUSH 图的对应 OSD 条目，它就不再接收数据了。你也可以反编译 CRUSH 图、删除 device 列表条目、删除对应的 host 桶条目或删除 host 桶（如果它在 CRUSH 图里，而且你想删除主机），重编译 CRUSH 图并应用它。详情参见<a class="reference external" href="../crush-map#removeosd">删除 OSD</a> 。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">crush</span> <span class="n">remove</span> <span class="p">{</span><span class="n">name</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>删除 OSD 认证密钥：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">auth</span> <span class="k">del</span> <span class="n">osd</span><span class="o">.</span><span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">ceph-{osd-num}</span></code> 路径里的 <code class="docutils literal notranslate"><span class="pre">ceph</span></code> 值是
<code class="docutils literal notranslate"><span class="pre">$cluster-$id</span></code> ，如果集群名字不是 <code class="docutils literal notranslate"><span class="pre">ceph</span></code> ，这里要更改。</p>
</li>
<li><p>删除 OSD 。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">rm</span> <span class="p">{</span><span class="n">osd</span><span class="o">-</span><span class="n">num</span><span class="p">}</span>
<span class="c1">#for example</span>
<span class="n">ceph</span> <span class="n">osd</span> <span class="n">rm</span> <span class="mi">1</span>
</pre></div>
</div>
</li>
</ol>
</div>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../add-or-rm-mons/" class="btn btn-neutral float-right" title="增加/删除监视器" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../change-mon-elections/" class="btn btn-neutral float-left" title="Configure Monitor Election Strategies" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>